<template>
	<div class="app-container">
		<el-table v-loading="loading" :data="postList">
			<el-table-column show-overflow-tooltip label="专题名称" width="300" align="center" prop="zoneName" />
			<el-table-column show-overflow-tooltip label="关联商品数量" align="center">
				<template slot-scope="scope">
					<el-link type="primary" :underline="true" @click="handlewh(scope.row,1)"
						:disabled="scope.row.collocationMethod != '0'">{{scope.row.goodsNumber}}
					</el-link>
				</template>
			</el-table-column>
			<el-table-column show-overflow-tooltip label="配置方式" align="center" prop="sortNumber">
				<template slot-scope="scope">
					<el-switch v-model="scope.row.collocationMethod" active-value="1" inactive-value="0"
						active-color="#13ce66" inactive-color="#ff4949" @change="handleChange(scope.row)">
					</el-switch>
					{{scope.row.collocationMethod == '0' ? '手动配置' : '自动配置' }}
				</template>
			</el-table-column>
			<el-table-column show-overflow-tooltip label="创建时间" align="center" prop="creatorTime">
				<template slot-scope="scope">
					{{scope.row.creatorTime | $YYYY_MM_DD_hh_mm_ss}}
				</template>
			</el-table-column>
			<el-table-column show-overflow-tooltip label="操作" align="center" width="140" fixed="right">
				<template slot-scope="scope">
					<el-link type="primary"
					 :disabled="scope.row.collocationMethod != '0'"
					 :underline="false" @click="handlewh(scope.row,2)">维护商品</el-link>
				</template>
			</el-table-column>
		</el-table>
		<pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
			@pagination="getList" />
		<zoneMaintenance ref="zone-maintenance" @success="getList"></zoneMaintenance>
	</div>
</template>

<script>
	import {
		listWcZoneGoods,
		updataWcZoneGoods
	} from "@/api/culturalCreativity/zone.js"
	import zoneMaintenance from "./zone-maintenance"
	export default {
		components: {
			zoneMaintenance
		},
		data() {
			return {
				loading: true,
				// 总条数
				total: 0,
				// 岗位表格数据
				postList: [],
				// 弹出层标题
				queryParams: {
					pageNum: 1,
					pageSize: 10
				},
			};
		},
		created() {
			this.getList();
		},
		methods: {
			async handleChange(row) {
				try {
					this.loading = true;
					console.log(row);
					let res = await updataWcZoneGoods(row);
					this.getList();
				} catch (e) {
					this.loading = false;
					//TODO handle the exception
				}
			},
			handlewh(e, state) {
				if(e.collocationMethod != '0') return;
				this.$refs['zone-maintenance'].init(e, state);
			},
			/** 查询岗位列表 */
			getList() {
				this.loading = true;
				listWcZoneGoods({}, this.queryParams).then(response => {
					this.postList = response.rows;
					this.total = response.total;
					this.loading = false;
				});
			},
			/** 搜索按钮操作 */
			handleQuery() {
				this.queryParams.pageNum = 1;
				this.getList();
			},
		}
	};
</script>
